/**
 * api管理
 */
import request from './../utils/request'
export default {
    // 登录接口
    login(params) {
        return request({
            url: '/users/login',
            method: 'post',
            data: params,
            mode: 'baseApi'
        })
    },
    // 获取本月登录记录和上月登录记录
    getUserLoginCount() {
        return request({
            url: '/userLogins/count',
            method: 'get',
            data: {},
            mode: 'baseApi'
        })
    },
    // 获取全部菜单列表
    getMenuList(params) {
        return request({
            url: '/menu/list',
            method: 'get',
            data: params,
            mode: 'baseApi'
        })
    },
    // 获取菜单权限列表
    getPermissionList() {
        return request({
            url: '/users/getPermissionList',
            method: 'get',
            data: {},
            mode: 'baseApi'
        })
    },
    // 获取用户列表
    getUserList(params) {
        return request({
            url: '/users/list',
            method: 'get',
            data: params,
            mode: 'baseApi'
        })
    },
    // 获取所有用户列表
    getAllUserList() {
        return request({
            url: '/users/all/list',
            method: 'get',
            data: {},
            mode: 'baseApi'
        })
    },
    // 删除用户
    userDel(params) {
        return request({
            url: '/users/delete',
            method: 'post',
            data: params,
            mode: 'baseApi'
        })
    },
    // 更新单个用户状态（启用/禁用）
    updateUserState(params) {
        return request({
            url: '/users/updateState',
            method: 'post',
            data: params,
            mode: 'baseApi'
        })
    },
    // 批量更新用户状态（启用/禁用）
    batchUpdateUserState(params) {
        return request({
            url: '/users/batchUpdateState',
            method: 'post',
            data: params,
            mode: 'baseApi'
        })
    },
    // 用户密码重置
    userPwdReset(params) {
        return request({
            url: '/users/pwdReset',
            method: 'post',
            data: params,
            mode: 'baseApi'
        })
    },
    // 获取所有角色列表
    getRoleAllList() {
        return request({
            url: '/roles/allList',
            method: 'get',
            data: {},
            mode: 'baseApi'
        })
    },
    // 获取角色列表
    getRoleList(params) {
        return request({
            url: '/roles/list',
            method: 'get',
            data: params,
            mode: 'baseApi'
        })
    },
    // 获取部门列表
    getDeptList(params) {
        return request({
            url: '/dept/list',
            method: 'get',
            data: params,
            mode: 'baseApi'
        })
    },
    // 部门操作
    deptOperate(params) {
        return request({
            url: '/dept/operate',
            method: 'post',
            data: params,
            mode: 'baseApi'
        })
    },
    // 用户提交接口
    userSubmit(params) {
        return request({
            url: '/users/operate',
            method: 'post',
            data: params,
            mode: 'baseApi'
        })
    },
    // 获取当前用户信息
    getCurrentUserInfo() {
        return request({
            url: '/users/current',
            method: 'get',
            data: {},
            mode: 'baseApi'
        })
    },
    // 更新当前用户信息
    updateUserInfo(params) {
        return request({
            url: '/users/updateCurrent',
            method: 'post',
            data: params,
            mode: 'baseApi'
        })
    },
    // 修改密码
    changePassword(params) {
        return request({
            url: '/users/changePassword',
            method: 'post',
            data: params,
            mode: 'baseApi'
        })
    },
    // 菜单提交接口
    menuSubmit(params) {
        return request({
            url: '/menu/operate',
            method: 'post',
            data: params,
            mode: 'baseApi'
        })
    },
    // 角色操作接口
    roleOperate(params) {
        return request({
            url: '/roles/operate',
            method: 'post',
            data: params,
            mode: 'baseApi'
        })
    },
    // 角色权限更新接口
    updatePermission(params) {
        return request({
            url: '/roles/update/permission',
            method: 'post',
            data: params,
            mode: 'baseApi'
        })
    },

    // 创建新对话会话
    createChatSession(params) {
        return request({
            url: '/chat/sessions',
            method: 'post',
            data: params,
            mode: 'chatApi'  // 对应Vite配置中的/chat-api代理
        })
    },

    // 获取用户的所有对话会话
    getChatSessions(params) {
        return request({
            url: '/chat/sessions',
            method: 'get',
            data: params,
            mode: 'chatApi'
        })
    },

    // 获取特定会话的历史记录
    getChatHistory(params) {
        return request({
            url: '/chat/history',
            method: 'get',
            data: params,
            mode: 'chatApi'
        })
    },

    // 非流式对话接口
    chat(params) {
        return request({
            url: '/chat',
            method: 'post',
            data: params,
            mode: 'chatApi'
        })
    },

    streamChat(params) {
        // 使用fetch API代替axios处理流式请求
        return fetch(`${config.chatApi}/chat`, {
            method: 'POST',
            headers: {
                'Content-Type': 'application/json',
                'Authorization': 'Bearer ' + (storage.getItem('userInfo')?.token || '')
            },
            body: JSON.stringify(params)
        })
    },
    // 删除对话会话
    deleteChatSession(params) {
        return request({
            url: '/chat/sessions',
            method: 'delete',
            data: params,
            mode: 'chatApi'
        })
    },

    // 修改会话标题
    updateSessionTitle(params) {
        return request({
            url: `/chat/sessions/${params.session_id}/title`,
            method: 'patch',
            data: {
                user_id: params.user_id,
                title: params.title
            },
            mode: 'chatApi'
        })
    }

}